cmake_minimum_required(VERSION 3.2)
# version 3.4 is required as other do not work with C++14 and clang

project(NodeEditor CXX)

set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES  ON)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

option(BUILD_EXAMPLES "Build Examples" ON)


# Find the QtWidgets library
find_package(Qt5 COMPONENTS
             Core
             Widgets
             Gui
             OpenGL)

add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")

if(MSVC)
  add_definitions(/Wall /EHsc)
else()
  add_definitions(-Wall -Wextra)
endif(MSVC)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#############################################################

file(GLOB_RECURSE LIB_CPPS  ./src/*.cpp )

qt5_add_resources(RESOURCES ./resources/resources.qrc)

# Tell CMake to create the helloworld executable
add_library(nodes SHARED ${LIB_CPPS} ${RESOURCES})

target_include_directories(nodes INTERFACE "include")

target_compile_definitions(nodes PUBLIC "-DNODE_EDITOR_SHARED")
target_compile_definitions(nodes PRIVATE "-DNODE_EDITOR_EXPORTS")

target_link_libraries(nodes
                      Qt5::Core
                      Qt5::Widgets
                      Qt5::Gui
                      Qt5::OpenGL)

if(BUILD_EXAMPLES)
  add_subdirectory(examples)
endif()
